// pages/JX/rank/rank.js
import S_request from '../../../utils/requestService.js';
import CONFIG from '../../../config.js';
import * as utils from '../../../utils/util.js';
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info: {},
    pageSize: 50,
    id: 0,
    treasure_id: 0,
    image_url: '',
    game_name: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let id = options.id;
    let treasure_id = options.treasure_id;
    let image_url = options.image_url;
    let game_name = options.game_name;
    this.setData({
      id: id,
      treasure_id: treasure_id,
      image_url: image_url,
      game_name:game_name
    })
    this.getRankList(id)
  },
  getRankList: function(id) {
    S_request.jx.getRankList(id, (result) => {
      let pay_status = result.treasure.pay_status;
      if (pay_status == 0) {
        result.txt = '邀请好友参加本次抽奖的人数越多，中奖概率越高。'
      } else {
        result.txt = '邀请最多者获得奖品。'
      }
      for (let i = 0; i < result.lists.length; i++) {
        let item = result.lists[i];
        if (i <= 2) {
          item.rank = "../image/rank_" + (i + 1) + ".png";
          item.showRank = true;
        } else {
          item.rank = i + 1;
          item.showRank = false;
        }
      }
      if (result.my != null) {
        if (result.my.order > 3) {
          result.my.rank = result.my.order;
        } else {
          result.my.rank = "../image/rank_" + result.my.order + ".png";
        }
      }
      this.setData({
        info: result
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    wx.showShareMenu({
      withShareTicket: false,
      success: function() {}
    });
    let nickname = '亲，'
    if (app.globalData.userInfo != null) {
      nickname = app.globalData.userInfo.nickName;
    }
    let url = encodeURIComponent('/pages/JX/detail/detail?id=' + this.data.id)
    let path = CONFIG.SHARE.pathDet + "&url=" + url + '&treasure_id=' + this.data.treasure_id
    console.log("path===" + path)
    let title = nickname + "邀请您参与【" + this.data.game_name + "】免费抽奖"
    let obj = { 'pagepath': CONFIG.SHARE.pathDet, 'url': url, 'treasure_id': this.data.treasure_id }
    S_request.jx.recordShare(this.data.treasure_id, obj);
    return {
      title: title,
      path: path,
      imageUrl: this.data.image_url,
      success: (res) => { //新版不走回调
        console.log("分享成功")
      }
    }
  }
})